<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%

	String id = request.getParameter("id");
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", "campus123");
	
		String select = "select * from UserRoute where ID = ?;";
		pstmt = conn.prepareStatement(select);
		pstmt.setString(1, id);
		ResultSet rs = pstmt.executeQuery();
		
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		while (rs.next()) {
			String key = rs.getString("Number");
			String routeid = rs.getString("ID");
			String route = rs.getString("Route");
			String startdate = rs.getString("StartDate");
			String enddate = rs.getString("EndDate");
			
			jo.put("Number", key);
			jo.put("ID", routeid);
			jo.put("Route", route);
			jo.put("StartDate", startdate);
			jo.put("EndDate", enddate);
			
			ja.add(jo);
		} 		
	
		out.print(ja);	
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>);